<template>
  <el-row type="flex" justify="space-between" align="middle" style="height: 40px;width: 100%;">
    <el-col :span="20">
      <span>{{ nodeData.name }}</span>
      <!-- {{ data }} -->
    </el-col>
    <el-col :span="4">
      <el-row type="flex">
        <!-- 两个内容 -->
        <el-col :span="12">{{ nodeData.manager }}</el-col>
        <el-col :span="12">
          <!-- 下拉菜单 element -->
          <el-dropdown @command="handleCommand">
            <span>
              操作<i class="el-icon-arrow-down" />
            </span>
            <!-- 下拉菜单 -->
            <!-- 自定义command事件 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item v-if="!isRoot" command="del">删除子部门</el-dropdown-item>
              <el-dropdown-item command="add">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" command="edit">修改部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
    <!-- <el-button type="text">点击打开 Message Box</el-button> -->
  </el-row>
</template>

<script>
import { delDepartmentsApi } from '@/api/department'
export default {
  props: {
    nodeData: {
      type: Object,
      required: true,
      default: () => {}
    },
    isRoot: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    handleCommand(cmd) {
      console.log(cmd)
      if (cmd === 'del') {
        console.log('删除按钮')
        this.$confirm('亲,你确定要删除吗', '温馨提示').then(async() => {
          const res = await delDepartmentsApi(this.nodeData.id)
          console.log(res)
          this.$message.success('删除成功')
          // 通知fu'z重新获取列表
          this.$emit('del-depts')
        })
      }
      if (cmd === 'add') {
        console.log('添加按钮')
        this.$emit('openDialog', this.nodeData)
      }
      if (cmd === 'edit') {
        console.log('修改按钮')
        this.$emit('editDialog', this.nodeData)
      }
    }
  }
}
</script>

<style lang="scss">

</style>
